<div class="box-body">
    <form class="layui-form" action="{:url('/wms/wlocation/save')}" method="post">
        <div class="layui-form-item">
            <label class="layui-form-label xrequired">所属区域</label>
            <div class="layui-input-block">
                <select id="area-id" name="area_id" lay-search lay-verify="required" lay-filter="area">
                    <option value="">请选择</option>
                    {foreach $area as $s}
                    <option {if isset($location) && $location.shelf.area_id == $s.area_id}selected{/if} value="{$s.area_id}">{$s.name}</option>
                    {/foreach}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label xrequired">所属货架</label>
            <div class="layui-input-block">
                <select id="shelf-id" name="shelf_id" lay-search lay-verify="required">
                    <option value="">请选择</option>
                    {if isset($shelf)}
                    {foreach $shelf as $s}
                    <option {if $location.shelf_id == $s.shelf_id}selected{/if} value="{$s.shelf_id}">{$s.code}</option>
                    {/foreach}
                    {/if}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">库位号</label>
            <div class="layui-input-block">
                <input type="text" autocomplete="off" placeholder="可自动生成"  name="code" {if isset($location)}value="{$location.code}"{/if} class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">所在层</label>
            <div class="layui-input-block">
                <input type="number" autocomplete="off" placeholder="在货架第几层数"  name="floor" {if isset($location)}value="{$location.floor}"{/if} class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">可放数量</label>
            <div class="layui-input-block">
                <input type="number" autocomplete="off" placeholder="库位最大可放数量"  name="max_qty" {if isset($location)}value="{$location.max_qty}"{/if} class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <input type="text" autocomplete="off" placeholder="备注"  name="remark" {if isset($location)}value="{$location.remark}"{/if} class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="checkbox" name="status" value="1" {if !isset($location) || (isset($location) && $location.status)}checked{/if} lay-skin="switch">
            </div>
        </div>
        {if isset($location)}
        <input type="hidden" name="location_id" value="{$location.location_id}">
        {/if}
    </form>
</div>
<script type="text/javascript">
layui.use(['layer', 'jquery', 'form'], function()
{
    var layer = layui.layer
        , form = layui.form
        , $ = layui.jquery;
    form.on("select(area)", function(data)
    {
        var wid = "{$curr_warehouse.warehouse_id}";
        if(!data.value || !wid) return false;
        $.get("{:url('/wms/wshelf/get')}", {warehouse_id: wid, area_id: data.value}).done(function(response)
        {
            if(response.code != 1)
            {
                layer.msg(response.msg, {icon: 5, time: 1500});
                return false;
            }
            var html = ["<option value=''>请选择</option>"];
            for(var i in response.data)
            {
                html.push("<option value='" + response.data[i].shelf_id + "'>" + response.data[i].code + "</option>");
            }
            $("#shelf-id").html(html.join(''));
            form.render('select');
        });
    });
});
</script>